<!--快讯-->
<template>
  <div class="all bg1">

    <div class="time">
      <text class="font26 text2">{{T('今天')+'  '+time}}</text>
    </div>
    <!--列表-->
    <list class="list" @loadmore="httpNewsLoading">
    
      <!--刷新-->
      <refresh @refresh="httpNews" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <!--内容-->
      <cell v-for="(item, index) in datas" v-bind:key="index">
        <!-- 内容 -->
        <VNews class="cell" :item="item" @share="shareClick" @report="reportClick"></VNews>

        <!-- 无更多数据 -->
        <div class="genduo" v-if="pageMax && (index == datas.length - 1)">
          <text class="font22 text3">{{T('没有更多数据')}}</text>
        </div>
      </cell>
    </list>
  </div>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
.load {
  height: 40px;
  width: 40px;

  margin-top: 20px;
  margin-left: 355px;
}
.genduo {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 750px;
  height: 100px;
}
.time {
  padding-left: 56px;
  padding-right: 15px;

  margin-top: 24px;
  margin-bottom: 15px;
}

/*********************** 列表*/
.list {
  flex: 1;
}
.cell {
  margin-left: 16px;
  margin-right: 16px;
  margin-top: 15px;
  margin-bottom: 15px;
}
</style>

<script>

//组件
import VNews from '@/square/view/VNews.vue' 

//功能
import jhttps from "@/_js/https";
import jconfig from "@/_js/config";
import jmodal from "@/_js/modal";
import jtime from "@/_js/time";

const weexFunction = weex.requireModule("WeexFunction");
import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {

  components: {
    VNews,
  },

  data() {
    return {
      T:T,
      Config:jconfig,
      time:'', //当前时间
      
      pageNo:0, //页码
      pageMax:false, //turn最大页面
      isRefresh:false, //显示刷新
      isLoadinging:false, //显示加载

      datas:[],
    };
  },

  created() {

    var time = jtime.getTime(undefined, 'y/M/d');
    var date = jtime.getTimeDate();
    this.time = time + ' ' + date;
    this.httpNews();
  },

  methods: {

    initData(datas) {

      for (let index = 0; index < datas.length; index++) {
        var data = datas[index];
        data.time = jtime.getTime(data.showTime, 'y/M/d H:m');
      }
      return datas;
    },

    /********************************* HTTP*/
    //http快讯列表-刷新
    httpNews() {
      if (this.isRefresh || this.isLoadinging) return;
      this.isRefresh = true;

      var param = {'pageNo':1};
      jhttps.post("flash/list",param,true,(data) => {
        this.isRefresh = false;
        if (data.status == 200) {

          data = data.data;
          this.datas = this.initData(data.flashList);
          this.pageNo = 1;
          this.pageMax = this.datas.length < 20;
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    //http快讯列表-加载
    httpNewsLoading() {
      if (this.pageMax || this.isRefresh || this.isLoadinging) return;
      this.isLoadinging = true;

      var param = {'pageNo': this.pageNo+1};
      jhttps.post("flash/list",param,true,(data) => {
          this.isLoadinging = false;
        if (data.status == 200) {

          data = data.data;
          var datas = this.initData(data.flashList);
          this.datas.push(...datas);
          this.pageNo++;
          this.pageMax = datas.length < 20;
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    /********************************* 点击*/
    //举报
    reportClick(item){
      jmodal.showLoad();
      setTimeout(() => {
        jmodal.hideLoad();
        jmodal.toast(T('举报成功'))
      }, 1000);
    },

    //分享
    shareClick(item) {
      var dict = {'title':item.title,
                  'content':item.content,
                  'time':item.time};
      weexFunction.shareWeex('share/ShareNew', {'param':dict});
    },
  },
};

</script>
